{include file="common/head"/}
<style>
    .table>thead>tr>th, .table>tbody>tr>th, .table>tfoot>tr>th, .table>thead>tr>td, .table>tbody>tr>td, .table>tfoot>tr>td{
        padding:0px;
        line-height:normal;
        vertical-align: middle;
        border-top: 0px;}
</style>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try{ace.settings.check('main-container' , 'fixed')}catch(e){}
    </script>
    {include file="common/left"}
    <div class="main-content">
        <div class="main-content-inner">
            {include file="common/header_nav"}
            <div class="page-content">
                <div class="page-header">
                    <h1>
                        您当前操作
                        <small>
                            <i class="ace-icon fa fa-angle-double-right"></i>
                            配置权限
                        </small>
                    </h1>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <form class="form-horizontal" name="groupSetaccess" id="groupSetaccess" method="post" action="{:url('groupSetaccess')}">
                            <input name="id" id="id" type="hidden" value="{$admin_group.group_id}"/>
                            <div class="form-group">
                                <div class="col-xs-12 col-sm-10 col-md-10">
                                    用户组名：<input type="text" name="title" id="title" value="{$admin_group.title}" disabled />
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <table class="table" border="0" align="center" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td height="30" style="border-bottom:#CCCCCC solid 1px; line-height:25px;">
                                        配置规则:<br/>
                                        1、由于页面原因，权限分配为三级，同时控制左侧导航以及用户权限<br/>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="30"
                                        style="border-bottom:#CCCCCC solid 1px; line-height:25px; background-color:#F4F8FB">
                                        <label class="pos-rel">
                                            <input type="checkbox" class="ace ace-checkbox-2"
                                                   id='chkAll' onclick='CheckAll(this.form)'
                                                   value="全选"/>
                                            <span class="lbl"> 权限全选</span>
                                        </label>
                                    </td>
                                </tr>
                                {foreach name="datab" item="vo"}
                                <tr>
                                    {php}
                                    $po_1=explode(',',$admin_group['rules']);
                                    {/php}
                                    <td height="50" style="border-bottom:#CCCCCC solid 1px;">
                                        <label>
                                            <input {if condition="in_array($vo['id'],$po_1)"}checked {/if} name="new_rules[]" class="ace ace-checkbox-2 checkbox-parent" type="checkbox" value="{$vo.id}" dataid="id-{$vo['id']}" />
                                            <span class="lbl"> <strong>{$vo.title}</strong></span>
                                        </label>
                                    </td>
                                </tr>
                                {foreach name="vo['sub']" item="sub"}
                                <tr>
                                    {php}
                                    $po_2=explode(',',$admin_group['rules']);
                                    {/php}
                                    <td height="40" style="padding-left:20px;border-bottom:#E7EBF8 dashed 1px!important; color:#333333">
                                        <label>
                                            <input {if condition="in_array($sub['id'],$po_2)"}checked{/if} name="new_rules[]" id="{$sub.id}" class="ace ace-checkbox-2 checkbox-parent checkbox-child" type="checkbox" value="{$sub.id}" dataid="id-{$vo['id']}-{$sub['id']}" />
                                            <span class="lbl"> {$sub.title}</span>
                                        </label>
                                    </td>
                                </tr>
                                {foreach name="sub['sub']" item="subb"}
                                <tr>
                                    <td height="30" style="padding-left:50px;border-bottom:#E7EBF8 dashed 1px!important; color:#666666">
                                        <label class="thopen">
                                            <input {if condition=" strpos($admin_group['rules'],','.$subb['id'].',') GT -1 "} checked {/if} name="new_rules[]" class="ace ace-checkbox-2 checkbox-parent checkbox-child" type="checkbox" id="{$subb.id}" value="{$subb.id}" dataid="id-{$vo['id']}-{$sub['id']}-{$subb['id']}"/>
                                            <span class="lbl" style="margin-right:20px;"> {$subb.title}</span>
                                        </label>
                                    </td>
                                </tr>
                                {if condition="!empty($subb['sub'])"}
                                <tr>
                                    <td height="30" style="padding-left:70px;border-bottom:#E7EBF8 dashed 1px; color:#666666">
                                        {volist name="subb['sub']" id="subbb"}
                                        <label class="thopen">
                                            <input {if condition=" strpos($admin_group['rules'],','.$subbb['id'].',') GT -1 "} checked {/if} name="new_rules[]" class="ace ace-checkbox-2 checkbox-child" type="checkbox" id="{$subbb.id}" value="{$subbb.id}" dataid="id-{$vo['id']}-{$sub['id']}-{$subb['id']}-{$subbb['id']}"/>
                                            <span class="lbl" style="margin-right:10px;"> {$subbb.title}</span>
                                        </label>
                                        {/volist}
                                    </td>
                                </tr>
                                {/if}
                                {/foreach}
                                {/foreach}
                                {/foreach}
                            </table>
                            <div class="clearfix form-actions">
                                <div class="col-md-offset-2 col-md-10">
                                    <button class="btn btn-info" type="submit">
                                        <i class="ace-icon fa fa-check bigger-110"></i>
                                        保存
                                    </button>

                                    &nbsp; &nbsp; &nbsp;
                                    <button class="btn" type="reset">
                                        <i class="ace-icon fa fa-undo bigger-110"></i>
                                        重置
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>



            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    {include file="common/foot" /}

</div><!-- /.main-container -->
<link rel="stylesheet" href="__STATIC__/assets/css/chosen.min.css"/>
<script src="__STATIC__/assets/js/chosen.jquery.min.js"></script>
<script type="text/javascript">
    //添加操作
    $(function () {
        $('#groupSetaccess').ajaxForm({
            beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });

        function checkForm() {

        }

        function complete(data) {
            if (data.status == 1) {
                layer.alert(data.info, {icon: 6}, function (index) {
                    layer.close(index);
                    window.location.href = data.url;
                });
            } else {
                layer.alert(data.msg, {icon: 5}, function (index) {
                    layer.close(index);
                });
                return false;
            }
        }
    });


    jQuery(function ($) {
        if (!ace.vars['touch']) {
            $('.chosen-select').chosen({allow_single_deselect: true});
            $(window)
                    .off('resize.chosen')
                    .on('resize.chosen', function () {
                        $('.chosen-select').each(function () {
                            var $this = $(this);
                            $this.next().css({'width': $this.parent().width()});
                        })
                    }).trigger('resize.chosen');

        }
    });
    $(function () {
        //动态选择框，上下级选中状态变化
        $('input.checkbox-parent').on('change', function () {
            var dataid = $(this).attr("dataid");
            $('input[dataid^=' + dataid + ']').prop('checked', $(this).is(':checked'));
        });
        $('input.checkbox-child').on('change', function () {
            var dataid = $(this).attr("dataid");
            dataid = dataid.substring(0, dataid.lastIndexOf("-"));
            var parent = $('input[dataid=' + dataid + ']');
            if ($(this).is(':checked')) {
                parent.prop('checked', true);
                //循环到顶级
                while (dataid.lastIndexOf("-") != 2) {
                    dataid = dataid.substring(0, dataid.lastIndexOf("-"));
                    parent = $('input[dataid=' + dataid + ']');
                    parent.prop('checked', true);
                }
            } else {
                //父级
                if ($('input[dataid^=' + dataid + '-]:checked').length == 0) {
                    parent.prop('checked', false);
                    //循环到顶级
                    while (dataid.lastIndexOf("-") != 2) {
                        dataid = dataid.substring(0, dataid.lastIndexOf("-"));
                        parent = $('input[dataid=' + dataid + ']');
                        if ($('input[dataid^=' + dataid + '-]:checked').length == 0) {
                            parent.prop('checked', false);
                        }
                    }
                }
            }
        });
        //AJAX提交
        $('#admin_group_runaccess').ajaxForm({
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });
        function complete(data) {
            if (data.status == 1) {
                layer.alert(data.info, {icon: 6}, function (index) {
                    layer.close(index);
                    window.location.href = data.url;
                });
            } else {
                layer.alert(data.info, {icon: 5}, function (index) {
                    layer.close(index);
                    window.location.href = "{:url('admin_group_list')}";
                });
                return false;
            }
        }
    });
    function unselectall() {
        if (document.myform.chkAll.checked) {
            document.myform.chkAll.checked = document.myform.chkAll.checked & 0;
        }
    }
    function CheckAll(form) {
        for (var i = 0; i < form.elements.length; i++) {
            var e = form.elements[i];
            if (e.Name != 'chkAll' && e.disabled == false)
                e.checked = form.chkAll.checked;
        }
    }

</script>
</body>
</html>